{% extends 'admin/base.html' %}
{% block title %}电影数据管理{% endblock %}
{% block content %}
    <form action="{{ url_for('admin.movie_manage_search') }}" id="search-form">
        <label for="search" class="input input-bordered flex gap-2 items-center w-full">
            <select name="form-class" class="focus-visible:outline-0 bg-transparent" id="search-class">
                <option value="movie-title"
                        {% if args and args.get('form-class') == 'movie-title' %}selected{% endif %}>电影名
                </option>
                <option value="movie-type" {% if args and args.get('form-class') == 'movie-type' %}selected{% endif %}>
                    分类
                </option>
            </select>
            <input type="text" class="flex flex-1" id="search-input" name="form-input"
                   value="{% if args %}{{ args.get('form-input') }}{% endif %}">
            <button type="submit">搜索</button>
        </label>
    </form>
    <div class="overflow-x-auto py-2">
        <table class="table table-pin-rows table-pin-cols">
            <!-- head -->
            <thead class="text-center">
            <tr>
                <td>电影名</td>
                <td>电影分类</td>
                <td>电影时长</td>
                <td>上映年份</td>
                <td>评价人数</td>
                <td>电影评分</td>
                <th>操作</th>
            </tr>
            </thead>
            <tbody class="text-center text-nowrap">
            <!-- row 1 -->
            {% if movie_manage %}
                {% if movie_manage.items | length > 0 %}
                    {% for i in movie_manage.items %}
                        <tr class="group">
                            <td class="group-hover:z-[30]">
                                <div class="flex items-center gap-4">
                                    <div class="avatar">
                                        <div class="h-20 w-14 rounded-lg group-hover:scale-150 group-hover:z-[30] transition-all">
                                            <a href="{{ i.info_url }}" target="_blank">
                                                <img src="{{ url_for('static', filename=i.img_url) }}"
                                                     alt="{{ i.title }}"/>
                                            </a>
                                        </div>

                                    </div>
                                    <div class="text-start">
                                        <div class="font-bold">
                                            <a href="{{ i.info_url }}" target="_blank">{{ i.title }}</a>
                                        </div>
                                        <div class="text-sm opacity-50">{{ i.director }}</div>
                                    </div>
                                </div>
                            </td>
                            <td>{{ i.movie_type }}</td>
                            <td>{{ i.film_length }}分钟</td>
                            <td>{{ i.year }}年</td>
                            <td>{{ i.people_num }}人</td>
                            <td>{{ i.score }}</td>
                            <th>
                                <a class="btn btn-error btn-sm text-white"
                                   href="{{ url_for('admin.movie_manage_del', id=i.id, page=movie_manage.page) }}">
                                    <span class="block md:hidden">
                                        <svg t="1720941470037" class="icon h-5 w-5" viewBox="0 0 1024 1024"
                                             version="1.1"
                                             xmlns="http://www.w3.org/2000/svg" p-id="4460"><path
                                                d="M253.2 268h516.6c-8.7 0-15.9-7.6-15.3-16.4L715.4 878c0.5-7.4 6.3-12.8 13.8-12.8H293.8c7.4 0 13.3 5.5 13.8 12.8l-39.1-626.4c0.5 8.7-6.6 16.4-15.3 16.4z m-2 613.6c1.4 22.4 20.2 40.1 42.6 40.1h435.3c22.4 0 41.2-17.8 42.6-40.1l39.1-626.4c1.5-23.9-17.2-43.7-41.1-43.7H253.2c-23.9 0-42.5 19.8-41.1 43.7l39.1 626.4zM878.7 268c15.6 0 28.3-12.6 28.3-28.2s-12.6-28.3-28.3-28.3H144.3c-15.6 0-28.3 12.6-28.3 28.3 0 15.6 12.6 28.2 28.3 28.2h734.4zM389 268h245c23.1 0 41.7-18.9 41.7-41.8v-81.8c0-23.1-18.8-41.8-41.7-41.8H389c-23.1 0-41.7 18.9-41.7 41.8v81.8c-0.1 23 18.7 41.8 41.7 41.8z m14.7-123.7c0 8.1-6.5 14.7-14.8 14.7h245c-8.2 0-14.8-6.5-14.8-14.7v81.8c0-8.1 6.5-14.7 14.8-14.7H389c8.2 0 14.8 6.5 14.8 14.7v-81.8z m174.7 626.6c0 15.6 12.6 28.2 28.3 28.2 15.6 0 28.2-12.6 28.2-28.2V362.3c0-15.6-12.6-28.2-28.2-28.2s-28.3 12.6-28.3 28.2v408.6zM444.5 362.3c0-15.6-12.6-28.2-28.2-28.2s-28.2 12.6-28.2 28.2v408.6c0 15.6 12.6 28.2 28.2 28.2s28.2-12.6 28.2-28.2V362.3z m0 0"
                                                fill="#ffffff" p-id="4461"></path></svg>
                                    </span>
                                    <span class="hidden md:block">删除</span>
                                </a>
                            </th>
                        </tr>
                    {% endfor %}
                {% else %}
                    <tr>
                        <td colspan="7">暂无数据</td>
                    </tr>
                {% endif %}
            {% endif %}
            </tbody>
        </table>
    </div>
    {% if movie_manage %}
        {% if movie_manage.pages > 1 %}
            <div class="join flex justify-center items-center mt-3">
                {% if movie_manage.has_prev %}
                    <a class="join-item btn"
                       href="{{ url_for(url_endpoint, page=movie_manage.prev_num, **(args if args else {})) }}">«</a>
                {% else %}
                    <a class="join-item btn" disabled>«</a>
                {% endif %}
                <button class="join-item btn">{{ movie_manage.page }} / {{ movie_manage.pages }}</button>
                <button class="join-item btn">数据量：{{ movie_manage.total }} 条</button>
                {% if movie_manage.has_next %}
                    <a class="join-item btn"
                       href="{{ url_for(url_endpoint, page=movie_manage.next_num, **(args if args else {})) }}">»</a>
                {% else %}
                    <a class="join-item btn" disabled>»</a>
                {% endif %}
            </div>
        {% endif %}
    {% endif %}
{% endblock %}